from odoo import fields, models, api, SUPERUSER_ID


class MrpWorkorder(models.Model):
    _inherit = 'mrp.workorder'

    @api.constrains('state')
    def constrains_s_state(self):
        for rec in self:
            if rec.state == 'done' and rec.s_station_order and not rec.s_station_order.done:
                rec.s_station_order.with_user(SUPERUSER_ID).with_delay().constrains_done()
